//
// Created by gastonfeng on 2022/11/22.
//

#ifndef RTE_KT1282_MASTER_ETHCLIENT_H
#define RTE_KT1282_MASTER_ETHCLIENT_H


#include "nStream.h"
#include "IPAddress.h"

class ethClient : public nStream {
public:
    ethClient();

    ~ethClient();

    explicit ethClient(uint8_t sock);

    explicit ethClient(struct tcp_struct *tcpClient);

    uint8_t status();

    virtual int connect(IPAddress ip, uint16_t port);

    virtual int connect(const char *host, uint16_t port);

    int write(uint8_t ch) override;

    int write(const uint8_t *buf, int size) override;

    int available() override;

    int available_wait(int Delay) override;

    int read() override;

    int read(uint8_t *buf, int size);

    int read_wait(int timeout = -1) override;

    int peek() override;

    void flush() override;

    virtual void stop();

    virtual uint8_t connected();

    virtual operator bool();

    virtual bool operator==(const bool value) {
        return bool() == value;
    }

    virtual bool operator!=(const bool value) {
        return bool() != value;
    }

    virtual bool operator==(const ethClient &);

    virtual bool operator!=(const ethClient &rhs) {
        return !this->operator==(rhs);
    };

    uint8_t getSocketNumber();

    virtual uint16_t localPort();;

    virtual IPAddress remoteIP();;

    virtual uint16_t remotePort();;

    void setTimeout(uint16_t timeout) {
        _timeout = timeout;
    }

    int tx_max_size() {
        return 536;
    }

    friend class EthernetServer;

    static void stopAllExcept(ethClient *pClient) {

    }

    int peekBytes(uint8_t *string, int i) {
        return 0;
    }

private:
    struct tcp_struct *_tcp_client{};
    uint16_t _timeout = 10000;
};


#endif //RTE_KT1282_MASTER_ETHCLIENT_H
